package com.hevs.samplewebapp.server.json;

import java.io.IOException;

import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

/**
 * Object used by Jackson to deserialize JSON key string to
 * com.google.appengine.api.datastore.Key
 * 
 * @author Arnaud Durand
 * @date 29.03.2012
 */
public class KeyDeserializer extends JsonDeserializer<Key> {

	/**
	 * Method to deserialize the Json
	 * @param jp
	 * Json to deserialize
	 * @param ctxt
	 * the context of deserialization
	 * @throws IOException, JsonProcessingException
	 * exception when the JSON isn't correct.
	 */
	@Override
	public Key deserialize(JsonParser jp, DeserializationContext ctxt)
			throws IOException, JsonProcessingException {
		return KeyFactory.stringToKey(jp.getText());
	}

}
